<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
  </head>
  <body>
    <script type="text/javascript">
      const _deleteRepeat = (array) => {
        // 补全代码
        /* 
    方法1：new Set(array) 
        */
        // return Array.from(new Set(array))
        /*
    方法二：newarr.indexOf(array)  
        */
        /*    var newarr = []
        for (var i = 0; i < array.length; i++) {
          if (newarr.indexOf(array[i]) === -1) {
            newarr.push(array[i])
          }
        }
        return newarr
        */
        /* 
    方法三:利用for嵌套循环 splice方法删除重复的元素
    */
        /*    for (var i = 0; i < array.length - 1; i++) {
          for (var j = i + 1; j < array.length; j++) {
            if (array[i] == array[j]) {
              array.splice(j, 1)
              j--
            }
          }
        }
        return array */
        /* 
      方法四：利用includes  用来判断一个数组是否包含一个指定的值
      */
        /*  var newarr = []
        for (var i = 0; i < array.length; i++) {
          if (!newarr.includes(array[i])) {
            newarr.push(array[i])
          }
        }
        return newarr */
        /* 
      方法五：filter
      */
        return array.filter((item, index, array) => {
          return array.indexOf(item, 0) === index
        })
      }
      console.log(_deleteRepeat([1, 2, 2, 2, 5, 4, 3, 1, 3]))
    </script>
  </body>
</html>
